﻿<%@ Page Language="C#" AutoEventWireup="true"%>

<form id="form1" runat="server">
    <div>
        <asp:scriptmanager id="ScriptManager1" runat="server">
        </asp:scriptmanager>
        <script type="text/javascript">
            //A function that will return a reference to the parent radWindow in case the page is loaded in a RadWindow object
            function getRadWindow() {
                var oWindow = null;
                if (window.radWindow) oWindow = window.radWindow;
                else if (window.frameElement.radWindow) oWindow = window.frameElement.radWindow;
                return oWindow;
            }

            function OnClientFileOpen(sender, args) {// Called when a file is open.
                var item = args.get_item();

                //If file (and not a folder) is selected - call the OnFileSelected method on the parent page
                if (item.get_type() == Telerik.Web.UI.FileExplorerItemType.File) {
                    // Cancel the default dialog;
                    args.set_cancel(true);

                    // get reference to the RadWindow
                    var wnd = getRadWindow();

                    //Get a reference to the opener parent page using RadWndow
                    var openerPage = wnd.BrowserWindow;

                    //if you need the URL for the item, use get_url() instead of get_path()
                    openerPage.OnFileSelected2(item.get_path()); // Call the method declared on the parent page


                    //Close the window which hosts this page
                    wnd.close();
                }
            }
        </script>
        <script type="text/javascript">
            //<![CDATA[
            function OnClientItemSelected(sender, args) {
                var pvwImage = $get("pvwImage");
                var imageSrc = args.get_item().get_url();

                if (imageSrc.match(/\.(gif|jpg)$/gi)) {
                    pvwImage.src = imageSrc;
                    pvwImage.style.display = "";
                }
                else {
                    pvwImage.src = imageSrc;
                    pvwImage.style.display = "none";
                }

            }
            //]]>
        </script>
        <table cellspacing="4">
            <tr>
                <td rowspan="2" style="vertical-align: top;">
                    <Telerik:RadFileExplorer runat="server" ID="RadFileExplorer1" Width="600px" Height="350px"
                        OnClientItemSelected="OnClientItemSelected" EnableOpenFile="false"
                        OnClientFileOpen="OnClientFileOpen" AllowPaging="True" PageSize="15" EnableFilterTextBox="True"
                        FilterTextBoxLabel="Nhập tên ảnh:">
                        <Configuration SearchPatterns="*.jpg,*.jpeg,*.gif,*.png" ViewPaths="~/Upload" DeletePaths="~/Upload"
                            UploadPaths="~/Upload"></Configuration>
                    </Telerik:RadFileExplorer>
                </td>
                <td>
                    <asp:label id="abc" runat="server"></asp:label>
                    <fieldset style="width: 140px; padding: 5px;">
                        <legend>Hình ảnh</legend>
                        <img id="pvwImage" src="" alt="" style="display: none; margin: 10px; width: 120px;" />
                    </fieldset>
                </td>
            </tr>
        </table>
    </div>
</form>


